'use strict';

const express = require('express');
const dbutility = require('../../common/dbutility');
const gputility = require('../../common/gputility');
const logger = require('../../common/logutility').logger('takExpCmp');
let router = express.Router();

router.get('/', function(req, res) {
    gputility.excuteGP(getGP(req, res));
});

function* getGP(req, res) {
    try {
        let cabNo = req.session.cabTak.cabNo;
        yield dbutility.cabModel.updateCabToNotInUse(cabNo);
        yield dbutility.expModel.updateExpToTaked(cabNo);
        res.render('./tak/takExpCmp', { cabNo });
    } catch (e) {
        logger.error(e);
        res.redirect('/error');
    }
}

module.exports = router;